import request from '@/utils/requset'
// 维护搜索热门数据的数据
import type { AllDetailsData, searchData, searchList } from './modules/search'

/**
 * @desc 获取热门搜索数据
 */
export const getPopularSearchApi = () => {
    return request.get<any, searchData>('/xhr/search/init.json')
}
/**
 * @desc 模糊搜索
 * @param keyWord 关键字
 */
// 获取模糊搜索数据
export const getKeywordApi = (keyWord: string) => {
    return request.post<any, string[]>(`/xhr/search/searchAutoComplete.json?keywordPrefix=${keyWord}`)
}
/**
 * @desc 商品列表
 * @param keyword 关键字
 */
export const getSearchDetailsApi = (keyword: string) => {
    const url = `/xhr/search/search.json?__
  timestamp=1630133434953&needPopWindow=true
  &searchWordSource=7&stillSearch=false&_stat_
  search=autoComplete&itemId=0&size=40&upperPr
  ice=-1&floorPrice=-1&matchType=0&categoryId=0
  &descSorted=false&sortType=0&keyword=${keyword}`
    return request.get<any, searchList>(url)
}
/**
 * @desc 获取商品详情
 * @param id 商品id
 * @returns Promise
 */
export const getDetailsApi = (id: string) => {
    return request.get<any, AllDetailsData>(`/item/detail.json?__timestamp=1673314611319&id=${id}`)
}